﻿using System;
using System.Web.UI.WebControls;
using AB.ServiceDirectory.Dao.DataFilters;
using Vladsm.Web.UI.WebControls;

namespace AB.ServiceDirectory.Design.WebUserControls.Lookup
{
    public partial class TypeOfBusinessLookup : System.Web.UI.UserControl
    {
        /// <summary>
        /// Handles the Load event of the Page control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                var filter = new BusinessFilters();
                ViewState["filter"] = filter;
            }
        }

        public void Popup()
        {
            PanelContainer.CssClass = "popup_container";
            PanelContainer.Visible = true;
        }

        /// <summary>
        /// Buttons the search click.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void ButtonSearchClick(object sender, EventArgs e)
        {
            var filter = ViewState["filter"] as BusinessFilters;
            if (filter != null)
            {
                filter.BussinessName = TextBoxBusinessName.Text;
                filter.SicCode = TextBoxSISCode.Text;
            }
            GridViewSearchBusiness.DataBind();
        }

        /// <summary>
        /// Buttons the clear click.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void ButtonClearClick(object sender, EventArgs e)
        {
            TextBoxBusinessName.Text = string.Empty;
            TextBoxSISCode.Text = string.Empty;
        }

        /// <summary>
        /// Buttons the none click.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void ButtonNoneClick(object sender, EventArgs e)
        {
            //GridViewSearchBusiness.DataSource = null;
            //GridViewSearchBusiness.DataBind();
        }

        /// <summary>
        /// Buttons the close click.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void ButtonCloseClick(object sender, EventArgs e)
        {
            PanelContainer.Visible = false;
        }

        /// <summary>
        /// Buttons the select click.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void ButtonSelectClick(object sender, EventArgs e)
        {
            foreach (GridViewRow businessGridView in GridViewSearchBusiness.Rows)
            {
                if (businessGridView.RowType == DataControlRowType.DataRow)
                {
                    var grd = (GroupRadioButton)businessGridView.FindControl("GroupRadioButton1");
                    if (grd != null && grd.Checked)
                    {
                        var dataKey = GridViewSearchBusiness.DataKeys[businessGridView.RowIndex];
                        if (businessGridView.RowIndex < 0)
                        {
                            return;
                        }
                        if (dataKey != null)
                        {
                            var key = (int)dataKey.Value;
                            //   TextBoxSISCode.Text = key.ToString();
                            //  GridViewSearchBusiness.DataSource = GetBusinessTypeById;
                            // var filter = ViewState["filter"] as BusinessFilters;
                        }
                        //  GridViewSearchBusiness.DataBind();
                    }

                }
            }
        }


        /// <summary>
        /// Handles the Selecting event of the BusinessTypeObjectDataSource control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Web.UI.WebControls.ObjectDataSourceSelectingEventArgs"/> instance containing the event data.</param>
        protected void BusinessTypeObjectDataSource_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
        {
            var filter = ViewState["filter"] as BusinessFilters;
            e.InputParameters["filter"] = filter;
        }
    }
}